package com.skyon.rule.res.resource;

/**
 * 是对外服务的实现
 * 
 * @author cfans
 */
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.skyon.rule.res.exceptions.BaseRuleException;
import com.skyon.rule.res.exceptions.DroolsFireException;
import com.skyon.rule.res.exceptions.DroolsInsertException;
import com.skyon.rule.res.exceptions.DynamicLoadException;
import com.skyon.rule.res.exceptions.PlotBuilderException;
import com.skyon.rule.res.model.InputParam;
import com.skyon.rule.res.model.OutputParam;
import com.skyon.rule.res.remoteInvoke.PlotInterface;
import com.skyon.rule.res.spring.PlotServerHelper;

@Component("plotResource")
public class PlotResource implements PlotInterface {
	@Autowired
	private PlotServerHelper plotServerTemplate;
	
	@Override
	public OutputParam callService(InputParam inpp) {
		OutputParam outpp = new OutputParam();
		//TODO 对传入的对象进行强制性校验
		
		//在这里调用规则引擎
		try {
			outpp = plotServerTemplate.execute(inpp);
		} catch (PlotBuilderException buildE) {
			outpp.getErrMsg().setErrorCode("-1");
			buildE.printStackTrace();
		} catch (DroolsFireException fireE) {
			outpp.getErrMsg().setErrorCode("-1");
			fireE.printStackTrace();
		} catch (DroolsInsertException insE) {
			outpp.getErrMsg().setErrorCode("-1");
			insE.printStackTrace();
		} catch (DynamicLoadException dyLoadE) {
			outpp.getErrMsg().setErrorCode("-1");
			dyLoadE.printStackTrace();
		} catch (BaseRuleException baseE) {
			outpp.getErrMsg().setErrorCode("-1");
			baseE.printStackTrace();
		} catch (Exception e) {
			outpp.getErrMsg().setErrorCode("-1");
			e.printStackTrace();
		}
		
		return outpp;
	}

	public void setPlotServerTemplate(PlotServerHelper plotServerTemplate) {
		this.plotServerTemplate = plotServerTemplate;
	}

}
